import {
    app,
    BrowserWindow
} from "electron";
import * as path from "path";
import Logger from "@main/plugins/logger/index";
import Plugins from "@main/plugins/index";
import "@main/updater/index.ts";

Plugins.register('logger', new Logger('main'));

function createWindow () {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
    });

    // console.log("NODE_ENV: ", process.env.NODE_ENV)
    if(process.env.VITE_DEV_SERVER_URL) {
        win.loadURL(process.env.VITE_DEV_SERVER_URL);
        win.webContents.openDevTools()
    } else {
        // 注意相对位置
        win.loadFile(
            path.join(__dirname, "../../dist/index.html")
        )
    }
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) {
            createWindow()
        }
    })
})
